<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>axios请求方法别名</title>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>

</head>
<body>
  <button id="btnGet">get请求</button>
  <button id="btnPost">post请求</button>
  <button id="btnUpdate">update请求</button>
  <button id="btnDelete">delete请求</button>

  <script>
    const oBtnGet = document.getElementById('btnGet')
    const oBtnPost = document.getElementById('btnPost')
    const oBtnUpdate = document.getElementById('btnUpdate')
    const oBtnDelete = document.getElementById('btnDelete')

    // get和Delete数据都是发送在url地址上，测试用请求都只需要传入用户iD 
    //也就是配置信息里的params信息即可
    oBtnGet.onclick =async function(){
        const re = await axios.get('/user',{
            params:{
                userID:'001'
            }
        })
        console.log(re.data);
    }
    oBtnDelete.onclick =async function(){
        const re = await axios.delete('/deleteuser',{
            params:{
                userID:'001'
            }
        })
        console.log(re.data);
    }
    

    // post和put的数据都在报文中  
    oBtnPost.onclick = async function(){
        // post请求post(url[, data[, config]]) 
        //这里data就是请求体数据，其他的不需要配置
        const re = await axios.post('/adduser',{
            name:'xiaoA',
            age:'18'
        })
        console.log(re.data);
    }
    //和post一致，把要新增或者修改的数据放上去

    oBtnUpdate.onclick = async function(){
        const re = await axios.put('/updateuser',{
            name:'xiaoB',
            age:'19'
        })
        console.log(re.data);
    }

    oBtnPost
  </script>
</body>
</html>